<script setup lang="ts">
import { getCurrentInstance, ref, watch, onBeforeMount, onMounted, onUpdated, nextTick } from 'vue'
import { onBeforeRouteLeave } from 'vue-router'
import { Swiper, SwiperSlide } from 'swiper/vue'
import 'swiper/css'
import MeScroll from 'mescroll.js'
import 'mescroll.js/mescroll.min.css'
const { proxy } = getCurrentInstance()

/* ---- */
const userInfo = proxy.$Store.get('userInfo') || {}
const WXConfig = proxy.$Store.get('WXConfig') || {}
const forSys = proxy.$Sys || []

/* --设置微信分享功能-- */
proxy.$WxTool.loadJsdk(WXConfig, (obj) => {
  if (!obj) return
  // ----
  obj.hideMenuItem()
})

/* ---- */
const forExtend = proxy.$route.query.exTend ? JSON.parse(proxy.$route.query.exTend) : {}
const forCount = proxy.$route.query.count || 0
const forIsCity = proxy.$route.query.isCity
// ----
let users = []
let agentCities = []
const myCitys = proxy.$City
// ----
let totalCount = 0
// ----
const infoSch = ref(null)
const forSearch = ref(proxy.$Store.get('forSearch') || {})
// ----
let tag = null
let tags = []
let tagText = null
const curTag = ref(null)
// ----
const isInteger = /^[1-9]\d*$/
let intends = []
// ----
const curProv = ref(null)
let myProvince = null
const myCity = ref(null)
let myDistrict = null
let myIndex = 0
const myCityData = proxy.$City
// ----
const tSpeed = 300
let bar = null
let clientWidth = 0
let navWidth = 0
let navSwiper = null
const navText = '全部'
const areas = ref([])
// --mescroll--
let noData = proxy.$Global.noData
let mescroll = null
const items = ref([])

/* ---- */
const sliding = ref()
const preImg = ref()
const pickerCity = ref()
const layer = ref()
const layerBox = ref()

/* ---- */
const setAppTitle = (title) => {
  document.title = title
  // --利用iframe的onload事件刷新页面--
  const iframe = document.createElement('iframe')
  iframe.style.visibility = 'hidden'
  iframe.style.width = 0
  iframe.style.height = 0
  document.body.appendChild(iframe)
  nextTick(() => { document.body.removeChild(iframe) })
}
// ----
const initAgentCityData = (items) => {
  items.forEach((item) => {
    myCitys.some((one) => {
      if (String(one.text) === String(item.province)) {
        if (one.children) {
          one.children.some((two) => {
            if (String(two.text) === String(item.city)) {
              if (two.children) {
                two.children.some((three) => {
                  if (String(three.text) === String(item.district)) three.class = 'xw-color-24'
                })
              } else {
                two.class = 'xw-color-24'
              }
            }
          })
        }
      }
    })
  })
}
// ----
const initData = () => {
  myCityData.some((one) => {
    if (Number(one.text.indexOf(myProvince)) !== Number(-1)) {
      if (one.children) {
        one.children.some((two) => {
          if (Number(two.text.indexOf(myCity.value)) !== Number(-1)) {
            if (two.children) {
              areas.value = two.children
              if (myDistrict) {
                two.children.some((three, index) => {
                  if (Number(three.text.indexOf(myDistrict)) !== Number(-1)) myIndex = index + 1
                })
              }
            } else {
              areas.value = []
            }
          }
        })
      }
    }
  })
}
// --initSwiperData || changeSwiperData--
const onSwiper = (swiper) => { navSwiper = swiper }
const initSwiper = (index) => {
  if (Number(areas.value.length) === 0) return false
  // --初始化--
  if (!navSwiper.el.querySelector('.bar')) {
    const newBar = document.createElement('div')
    newBar.setAttribute('class', 'bar')
    newBar.innerHTML = '<span class="xw-anim"></span>'
    navSwiper.wrapperEl.appendChild(newBar)
  }
  bar = navSwiper.el.querySelector('.bar')
  navSwiper.slides[navSwiper.activeIndex].querySelector('span').style.color = '#3388ff'
  // --Nav的可视宽度--
  clientWidth = navSwiper.wrapperEl.offsetWidth
  navWidth = 0
  for (let i = 0; i < navSwiper.slides.length; i++) {
    navWidth += navSwiper.slides[i].offsetWidth
  }
  // --点击slide事件--
  navSwiper.on('tap', () => {
    swiperMescroll(navSwiper.clickedIndex)
    // ----
    const newItems = []
    if (navSwiper.slides[navSwiper.clickedIndex].querySelector('span').innerText !== String(navText)) newItems.push(navSwiper.slides[navSwiper.clickedIndex].querySelector('span').innerText)
    proxy.$Myfun.setSearchRes(proxy, newItems, ['district'], (result) => { forSearch.value = result })
  })
  // ----
  setTimeout(() => { swiperMescroll(index) }, 100)
}
const swiperMescroll = (index) => {
  const clickIndex = index
  const clickSlide = navSwiper.slides[clickIndex]
  const activeSlidePosition = navSwiper.slides[clickIndex].offsetLeft

  // --释放时导航移动过渡--
  bar.style.transitionDuration = tSpeed + 'ms'
  bar.style.width = clickSlide.offsetWidth + 'px'
  bar.querySelector('span').style.width = clickSlide.querySelector('span').offsetWidth + 'px'
  bar.style.transform = 'translateX(' + activeSlidePosition + 'px)'

  // --导航居中--
  const navSlideWidth = clickSlide.offsetWidth
  // --activeSlide距左边的距离--
  const navActiveSlideLeft = navSwiper.slides[clickIndex].offsetLeft

  navSwiper.setTransition(tSpeed)
  if (navWidth > clientWidth) {
    if (navActiveSlideLeft < (clientWidth - navSlideWidth) / 2) {
      navSwiper.setTranslate(0)
    } else if (navActiveSlideLeft > navWidth - (navSlideWidth + clientWidth) / 2) {
      navSwiper.setTranslate(clientWidth - navWidth)
    } else {
      navSwiper.setTranslate((clientWidth - navSlideWidth) / 2 - navActiveSlideLeft)
    }
  }

  navSwiper.slides.forEach((current) => { current.querySelector('span').style.color = '#111111' })
  clickSlide.style.transitionDuration = tSpeed + 'ms'
  clickSlide.querySelector('span').style.color = '#3388ff'
}
// ----
const setPublicInfo = async (item, callback) => {
  await proxy.$http[item.type](item.url, item.data).then((res) => {
    if (res) callback && callback(res)
  }).catch((err) => { proxy.$Myfun.forToast(layer.value, 'open', err) })
}
// ----
const setFuncOpen = (name, item, extra, callback, isFunc) => {
  const deadline = item.funcs
  const forStarttime = proxy.$Myfun.getToday()
  const forEndtime = proxy.$Myfun.getNewDate({num: 2})
  const isFuncInfo = deadline.some((curItem) => {
    if (String(curItem.name) === String(name)) {
      curItem.starttime = forStarttime
      curItem.endtime = forEndtime
      return true
    }
  })
  if (!isFuncInfo) {
    let theItem = {
      name: name,
      starttime: forStarttime,
      endtime: forEndtime
    }
    if (isFunc) {
      const forCurIntend = []
      item.intends.forEach((curItem) => {
        if (curItem.light) forCurIntend.push(curItem.id)
      })
      theItem = {
        name: name,
        intend: forCurIntend,
        starttime: forStarttime,
        endtime: forEndtime
      }
    }
    deadline.push(theItem)
  }
  const forLineData = JSON.stringify(deadline)
  // ----
  let forData = {
    topuptw: forLineData,
    // ----
    config_id: userInfo.config_id,
    openid: userInfo.openid
  }
  Object.assign(forData, extra)
  setPublicInfo({
    type: 'patch',
    url: 'dealer/update?id=' + item.id,
    data: forData
  }, (res) => { callback && callback(forEndtime) })
}
// ----
const changeAppTitle = () => {
  const forTitle = forExtend.title ? forExtend.title + '（' + totalCount + '）' : document.title
  setAppTitle(forTitle)
}
// ----
const getCurrencyInfo = async (callback) => {
  // --获取功能意向--
  const intendItems = forSys.filter((item) => { return String(item.name) === 'market_payIntend' })
  if (Number(intendItems.length) === 1) {
    proxy.$Myfun.getJsonData(intendItems[0].value, (resJson) => {
      if (resJson[0].list && Number(resJson[0].list.length) > 0) intends = resJson[0].list
    })
  }
  // --获取所有用户信息 && 行业分类 && 区域运营商代理地区--
  const forUserData = {
    params: {
      page: 1,
      PageSize: 1000000000000
    }
  }
  const forTagData = {
    params: {
      sort: 'SORT_ASC',
      // ----
      page: 1,
      PageSize: 1000000
    }
  }
  const forAgentCityData = {
    params: {
      page: 1,
      PageSize: 1000000
    }
  }
  await proxy.$Axios.all([
    proxy.$Axios.get('dealer/index', forUserData),
    proxy.$Axios.get('maincate/index', forTagData),
    proxy.$Axios.get('agent-set/index', forAgentCityData)
  ]).then(proxy.$Axios.spread((userData, tagData, agentCityData) => {
    // --所有用户信息--
    const userItems = []
    userData.items.forEach((item, index) => {
      userItems.push({
        id: String(item.id),
        sn: item.sn,
        telphone: item.telphone
      })
    })
    users = userItems
    // --行业分类--
    const tagItems = []
    tagData.items.forEach((item, index) => {
      tagItems.push({
        value: String(item.id),
        text: proxy.$Myfun.setText(item.name)
      })
    })
    tags = tagItems
    // --区域运营商代理地区--
    agentCities = agentCityData.items
  })).catch((err) => { proxy.$Myfun.forToast(layer.value, 'open', err) })
  // ----
  if (Number(agentCities.length) > 0) initAgentCityData(agentCities)
  // --设置网页title--
  changeAppTitle()
  // ----
  callback && callback()
}
// --getData--
const startMeScroll = () => {
  mescroll = new MeScroll(proxy.$refs.dataScroll, {
    up: {
      callback: getListData,
      isBounce: false,
      page: { num: 0, size: 10 },
      htmlNodata: '<p class="upwarp-nodata">-- 到底啦 --</p>',
      noMoreSize: 10,
      toTop: {
        src: '/pics/mescroll-totop.png',
        offset: 1000
      },
      empty: {
        warpId: proxy.$refs.dataList,
        tip: noData
      }
    }
  })
}
const getListData = (page) => {
  let forCitySch = undefined
  if (forIsCity && myProvince && myCity.value) {
    const newCitySch = {
      province: myProvince,
      city: myCity.value
    }
    if (myDistrict) newCitySch.district = myDistrict
    forCitySch = JSON.stringify(newCitySch).replace(/{/g, '').replace(/}/g, '')
  }
  // ----
  let extra = {
    params: {
      'DealerSearch[telphone]': infoSch.value,
      // ----
      'DealerSearch[maincate_id]': tag ? ',' + tag + ',' : undefined,
      // ----
      'DealerSearch[topupth]': forCitySch,
      // ----
      page: page.num,
      PageSize: page.size
    }
  }
  if (!isInteger.test(infoSch.value)) {
    extra = {
      params: {
        'DealerSearch[name]': infoSch.value,
        // ----
        'DealerSearch[maincate_id]': tag ? ',' + tag + ',' : undefined,
        // ----
        'DealerSearch[topupth]': forCitySch,
        // ----
        page: page.num,
        PageSize: page.size
      }
    }
  }
  Object.assign(extra.params, forExtend.data)
  // ----
  getListDataFromNet({
    forUrl: 'dealer/index',
    forData: extra
  }, page.num, page.size, (curPageData) => {
    setListData(curPageData).then((result) => {
      if (Number(result.length) > 0) {
        mescroll.endSuccess(curPageData.length, true)
      } else {
        mescroll.endSuccess(0, true)
      }
      items.value = items.value.concat(result)
    })
  }, (resMsg) => {
    mescroll.endErr()
    proxy.$Myfun.forToast(layer.value, 'open', resMsg)
  })
}
const getListDataFromNet = (option, pageNum, pageSize, successCallback, errorCallback) => {
  if (Number(pageNum) === 1) {
    if (document.querySelector('.upwarp-nodata')) { document.querySelector('.upwarp-nodata').style.visibility = 'hidden' }
    items.value = []
  }
  // ----
  proxy.$http.get(option.forUrl, option.forData).then((res) => {
    totalCount = res._meta.totalCount + Number(forCount)
    // --设置网页title--
    changeAppTitle()
    // ----
    successCallback && successCallback(res.items)
  }).catch((err) => { errorCallback && errorCallback(err) })
}
const setListData = async (items) => {
  const newItems = []
  // ----
  for (let i = 0; i < Number(items.length); i++) {
    const item = items[i]
    // ----
    if (String(item.telphone) === String(proxy.$Phone)) continue
    // ----
    let funcLine = []
    proxy.$Myfun.getJsonData(item.topuptw, (resJson) => { funcLine = resJson })
    // ----
    let selfIntends = []
    funcLine.some((oneItem) => {
      if (String(oneItem.name) === 'operat') selfIntends = oneItem.intend
    })
    let forSalesmanCanTap = false
    let forSalerCanTap = false
    let forExhibitionCanTap = false
    const forIntends = []
    intends.forEach((oneItem) => {
      const forLight = selfIntends.some((twoItem) => {
        if (Number(oneItem.id) === Number(twoItem)) {
          if (String(oneItem.key) === 'salesman') forSalesmanCanTap = true
          if (String(oneItem.key) === 'saler') forSalerCanTap = true
          if (String(oneItem.key) === 'exhibition') forExhibitionCanTap = true
          return true
        }
      })
      forIntends.push({
        id: oneItem.id,
        light: forLight,
        text: proxy.$Myfun.setText(oneItem.text)
      })
    })
    // ----
    let forSalesmanTime = ''
    funcLine.some((oneItem) => {
      if (String(oneItem.name) === 'salesman') forSalesmanTime = String(oneItem.endtime).split(' ')[0]
    })
    let forSalerTime = ''
    funcLine.some((oneItem) => {
      if (String(oneItem.name) === 'saler') forSalerTime = String(oneItem.endtime).split(' ')[0]
    })
    let forExhibitionTime = ''
    funcLine.some((oneItem) => {
      if (String(oneItem.name) === 'exhibition') forExhibitionTime = String(oneItem.endtime).split(' ')[0]
    })
    let forAgentCity = ''
    await proxy.$Myfun.getJsonData(item.topupth, (resJson) => {
      if (Number(resJson.length) > 0) {
        const CData = resJson[0]
        if (CData.district) {
          forAgentCity = CData.province + ' - ' + CData.city + ' - ' + CData.district
        } else if (CData.city) {
          forAgentCity = CData.province + ' - ' + CData.city
        } else if (CData.province) {
          forAgentCity = CData.province
        }
      }
    })
    // ----
    let forImg = ''
    const advItems = []
    await proxy.$Myfun.getJsonData(item.intention, (resJson) => {
      if (Number(resJson.length) > 0) forImg = resJson[0].image
      // ----
      resJson.forEach((theItem) => {
        advItems.push({
          msrc: theItem.image,
          src: theItem.image,
          width: theItem.width,
          height: theItem.height,
          alt: ''
        })
      })
    })
    // ----
    let forSN = ''
    let forTelphone = ''
    users.some((theItem) => {
      if (String(theItem.id) === String(item.parent_dealer_id)) {
        forSN = proxy.$Myfun.setText(theItem.sn)
        forTelphone = proxy.$Myfun.setText(theItem.telphone)
      }
    })
    // ----
    newItems.push({
      id: item.id,
      sn: item.sn,
      name: proxy.$Myfun.setText(item.name),
      desc: proxy.$Myfun.setText(item.remark),
      leader: proxy.$Myfun.setText(item.leader),
      telphone: item.telphone,
      created_at: proxy.$Myfun.getDateShort(item.created_at),
      // ----
      image: forImg,
      advs: advItems,
      // ----
      funcs: funcLine,
      // ----
      salesmanCanTap: forSalesmanCanTap,
      salerCanTap: forSalerCanTap,
      exhibitionCanTap: forExhibitionCanTap,
      // ----
      intends: forIntends,
      // ----
      salesmanTime: forSalesmanTime,
      salerTime: forSalerTime,
      exhibitionTime: forExhibitionTime,
      agentCity: forAgentCity,
      // ----
      isOpenOperat: Number(item.is_agent) === 1,
      isOpenStoped: Number(item.is_stoped) === 1,
      isOpenSalesman: Number(item.is_salesman) === 1,
      isOpenSaler: Number(item.is_saler) === 1,
      isOpenExhibition: Number(item.is_exhibition) === 1,
      isOpenWhole: Number(item.is_warehouse) === 1,
      // ----
      parent_id: item.parent_dealer_id,
      parent_sn: forSN,
      parent_telphone: forTelphone
    })
  }
  return newItems
}
const divScroll = (event) => { proxy.$Myfun.setImgToTop() }
// ----
const emptyInfo = (event) => {
  const curEL = event.currentTarget
  const input = curEL.parentElement.querySelector('input')
  input.value = ''
  input.dispatchEvent(new Event('input'))
  // ----
  getHeadFun(1)
}
// ----
const getHeadFun = (type, item) => {
  switch (Number(type)) {
    case 1: {
      const newItems = []
      newItems.push(infoSch.value)
      proxy.$Myfun.setSearchRes(proxy, newItems, ['infoSch'], (result) => { forSearch.value = result })
      break
    }
    case 2: {
      const options = {
        type: 1,
        forall: { show: true, text: '不限地区' },
        slideName: 'slideRight',
        boxClass: 'SLB-box-right',
        itemName: myProvince || '',
        childName: myCity.value || '',
        title: '选择地区',
        list: myCityData,
        callback: (info) => {
          proxy.$Myfun.setSearchRes(proxy, info, ['province', 'city'], (result) => { forSearch.value = result })
        }
      }
      proxy.$Myfun.isIndepth(sliding.value, 'open', options)
      break
    }
    case 3: {
      const options = {
        type: 0,
        forall: { show: true, text: '不限行业' },
        slideName: 'slideRight',
        boxClass: 'SLB-box-right',
        itemName: tagText || '',
        title: '选择行业',
        list: tags,
        callback: (info) => {
          proxy.$Myfun.setSearchRes(proxy, info, ['tagText', 'tag'], (result) => { forSearch.value = result })
        }
      }
      proxy.$Myfun.isIndepth(sliding.value, 'open', options)
      break
    }
  }
}
const getAuditFun = (type, item, event) => {
  switch (Number(type)) {
    case 1: {
      if (Number(item.advs.length) > 0) {
        const curEL = event.currentTarget
        const options = {
          actElement: curEL,
          addopt: {
            loop: true,
            dataSource: item.advs
          }
        }
        proxy.$Myfun.isIndepth(preImg.value, 'openPhotoSwipe', options)
      }
      break
    }
    case 2: {
      proxy.$Myfun.openPage(proxy, 'push', 'GoodsHome', { dealer_id: item.id })
      break
    }
    case 3: {
      window.location.href = 'tel:' + item.telphone
      break
    }
    case 4: {
      proxy.$Myfun.openPage(proxy, 'push', 'ForPayRecord', { dealer_id: item.id })
      break
    }
    case 5: {
      let curField = 1
      if (item.isOpenStoped) curField = -1
      // ----
      setPublicInfo({
        type: 'patch',
        url: 'dealer/update?id=' + item.id,
        data: {
          is_stoped: curField,
          // ----
          is_popularize: Number(curField) === 1 ? undefined : 0,
          // ----
          config_id: userInfo.config_id,
          openid: userInfo.openid
        }
      }, async (res) => {
        if (!item.isOpenStoped) {
          await proxy.$http.post('user/send-pubsms', {
            telphone: item.telphone,
            tmpid: 'SMS_269505369',
            // ----
            config_id: userInfo.config_id,
            openid: userInfo.openid
          }).then((res) => {}).catch((err) => { proxy.$Myfun.forToast(layer.value, 'open', err) })
        }
        // --重新请求数据--
        mescroll.scrollTo(0)
        mescroll.resetUpScroll()
      })
      break
    }
    case 6: {
      if (!item.isOpenOperat) return false
      // ----
      if (!item.salesmanCanTap) return false
      if (item.isOpenSalesman) return false
      if (item.isOpenSaler) return false
      if (item.isOpenExhibition) return false
      // ----
      const options = {
        content: '选择代理地区 省-市-区/县',
        button: [{
          text: proxy.$Global.layer.btnCancel
        }, {
          text: '确定选择',
          class: 'xw-color-24',
          callback: () => {
            layerBox.value.close()
            // ----
            const options = {
              type: 3,
              button: ['取消', '确定'],
              initData: myCitys,
              yes: (result) => {
                const agentCitySchObj = {
                  province: result[0].text || '',
                  city: result[1].text || '',
                  district: result[2] ? result[2].text : ''
                }
                const forAgentCitySch = JSON.stringify(agentCitySchObj)
                // ----
                const isAgentCityInfo = agentCities.some((curItem) => {
                  if (String(curItem.province) === String(agentCitySchObj.province) && String(curItem.city) === String(agentCitySchObj.city) && String(curItem.district) === String(agentCitySchObj.district)) return true
                })
                if (isAgentCityInfo) {
                  proxy.$Myfun.forToast(layer.value, 'open', '该地区已存在代理，禁止选择')
                } else {
                  setFuncOpen('salesman', item, { is_salesman: 1 }, (info) => {
                    setPublicInfo({
                      type: 'post',
                      url: 'agent-set/create',
                      data: {
                        province: agentCitySchObj.province || undefined,
                        city: agentCitySchObj.city || undefined,
                        district: agentCitySchObj.district || undefined,
                        dealer_id: item.id,
                        deadline: info,
                        // ----
                        config_id: userInfo.config_id,
                        openid: userInfo.openid
                      }
                    }, (res) => {
                      const agentCityItems = agentCities
                      agentCityItems.push(res)
                      initAgentCityData(agentCityItems)
                    })
                    // ----
                    setFuncOpen('operat', item, {}, () => {
                      setPublicInfo({
                        type: 'patch',
                        url: 'dealer/update?id=' + item.id,
                        data: {
                          topupth: forAgentCitySch,
                          // ----
                          config_id: userInfo.config_id,
                          openid: userInfo.openid
                        }
                      }, (res) => {
                        // --重新请求数据--
                        mescroll.scrollTo(0)
                        mescroll.resetUpScroll()
                      })
                    }, true)
                  })
                }
              }
            }
            proxy.$Myfun.isIndepth(pickerCity.value, 'open', options)
          }
        }]
      }
      proxy.$Myfun.isIndepth(layerBox.value, 'open', options)
      break
    }
    case 7: {
      if (!item.isOpenOperat) return false
      // ----
      if (!item.salerCanTap) return false
      if (item.isOpenSaler) return false
      if (item.isOpenSalesman) return false
      if (item.isOpenExhibition) return false
      // ----
      setFuncOpen('saler', item, { is_saler: 1 }, (info) => {
        setFuncOpen('operat', item, {}, () => {
          // --重新请求数据--
          mescroll.scrollTo(0)
          mescroll.resetUpScroll()
        }, true)
      })
      break
    }
    case 8: { //战略合作商单独处理
      // if (!item.isOpenOperat) return false
      // // ----
      // if (!item.exhibitionCanTap) return false
      // if (item.isOpenExhibition) return false
      // if (item.isOpenSalesman) return false
      // if (item.isOpenSaler) return false
      let isCanClick = false;
      item.intends.forEach(v => {
        if(v.text.indexOf('战略合作商') > 0){
          isCanClick = v.light
        }
      })
      
      if(isCanClick && forExtend.title == "申请合作商"){
        setFuncOpen('exhibition', item, { is_exhibition: (forExtend.data['DealerSearch[is_exhibition]']==1?0:1) }, (info) => {
          setFuncOpen('operat', item, {}, () => {
            // --重新请求数据--
            mescroll.scrollTo(0)
            mescroll.resetUpScroll()
          }, true)
        })
      } 
      break
    }
    case 9: {
      let curField = 1
      if (item.isOpenWhole) curField = -1
      // ----
      setPublicInfo({
        type: 'patch',
        url: 'dealer/update?id=' + item.id,
        data: {
          is_warehouse: curField,
          // ----
          config_id: userInfo.config_id,
          openid: userInfo.openid
        }
      }, (res) => {
        // --重新请求数据--
        mescroll.scrollTo(0)
        mescroll.resetUpScroll()
      })
      break
    }
  }
}

/* ---- */
watch(() => forSearch.value, (newVal, oldVal) => {
  infoSch.value = newVal.infoSch
  // ----
  if (forIsCity) {
    curProv.value = newVal.province || '选择地区'
    // ----
    myProvince = newVal.province
    myCity.value = newVal.city
    myDistrict = newVal.district
    // ----
    if (String(newVal.province) !== String(oldVal.province) || String(newVal.city) !== String(oldVal.city)) {
      myDistrict = null
      myIndex = 0
      // ----
      proxy.$Myfun.setSearchRes(proxy, [myProvince, myCity.value], ['province', 'city', 'district'], (result) => { forSearch.value = result })
      // ----
      if (myProvince && myCity.value) {
        initData()
        nextTick(() => { initSwiper(myIndex) })
      }
    } else {
      // --重新请求数据--
      mescroll.scrollTo(0)
      mescroll.resetUpScroll()
    }
  } else {
    curTag.value = newVal.tagText || '选择行业'
    // ----
    tag = newVal.tag
    tagText = newVal.tagText
    // --重新请求数据--
    mescroll.scrollTo(0)
    mescroll.resetUpScroll()
  }
}, { deep: true })

/* ---- */
onBeforeMount(() => {
  infoSch.value = forSearch.value.infoSch
  // ----
  if (forIsCity) {
    curProv.value = forSearch.value.province || '选择地区'
    // ----
    myProvince = forSearch.value.province
    myCity.value = forSearch.value.city
    myDistrict = forSearch.value.district
  } else {
    curTag.value = forSearch.value.tagText || '选择行业'
    // ----
    tag = forSearch.value.tag
    tagText = forSearch.value.tagText
  }
})
onMounted(() => {
  if (forIsCity && myProvince && myCity.value) {
    initData()
    nextTick(() => { initSwiper(myIndex) })
  }
  // ----
  getCurrencyInfo(() => {
    // --创建MeScroll对象--
    setTimeout(() => { startMeScroll() }, 500)
  })
})
onUpdated(() => { nextTick(() => { proxy.$Myfun.setSectionH() }) })
onBeforeRouteLeave(() => {
  if (mescroll) mescroll.destroy()
  proxy.$Store.remove('forSearch')
})
</script>

<template>
  <div>
    <header class="xw-bg-gray">
      <div class="forTop xw-flex xw-flex-align">
        <div class="TOP-sch xw-bg-white xw-radius-3 xw-flex-W1 xw-flex xw-flex-align">
          <em class="far fa-search TOP-L"></em>
          <p class="xw-flex-W1"><input class="schText" type="text" placeholder="输入关键词或注册手机号找会员" v-model.trim="infoSch"/></p>
          <transition name="fade"><em class="fa fa-times-circle" @click="emptyInfo" v-if="infoSch"></em></transition>
          <span class="TOP-btn TOP-R xw-Lfg" @click="getHeadFun(1)">搜索</span>
        </div>
        <a class="TOP-grap TOP-R xw-flex xw-flex-center" @click="getHeadFun(2)" v-if="forIsCity">
          <span><em class="fa fa-compass xw-color-12"></em>{{curProv}}</span>
        </a>
        <a class="TOP-grap TOP-R xw-flex xw-flex-center" @click="getHeadFun(3)" v-else>
          <span><em class="fa fa-compass xw-color-12"></em>{{curTag}}</span>
        </a>
      </div>
      <div class="forNav xw-flex xw-flex-align" v-if="forIsCity && myCity">
        <span class="FNV-title FNV-L xw-Rfg">{{myCity}}</span>
        <div class="FNV-menu xw-flex-W1">
          <div class="FNV-box FNV-L FNV-R" v-if="Number(areas.length) > 0">
            <swiper :slides-per-view="'auto'" :freeMode="true" @swiper="onSwiper">
              <swiper-slide><span class="xw-middle">{{navText}}</span></swiper-slide>
              <swiper-slide v-for="(item, index) in areas"><span class="xw-middle">{{item.text}}</span></swiper-slide>
            </swiper>
          </div>
          <p class="xw-noData xw-middle" v-else >该地区无区县</p>
        </div>
      </div>
    </header>
    <div class="xw-section">
      <div ref="dataScroll" class="mescroll" @scroll="divScroll">
        <ul class="list-user xw-flex xw-flex-column" ref="dataList">
          <li class="xw-bg-white xw-radius-3" v-for="(item, index) in items">
            <div class="LUR-con xw-act xw-flex xw-flex-align" @click="getAuditFun(1, item, $event)" v-if="Number(item.advs.length) > 0 || item.name || item.desc">
              <div class="LUR-avar xw-radius-3" v-if="item.image"><div class="xw-bgImg" :style="{ backgroundImage: 'url(' + item.image + ')' }"></div></div>
              <div class="LUR-name xw-flex-W1" v-if="item.name || item.desc">
                <h1 class="xw-ellipsis-2" v-if="item.name">{{item.name}}</h1>
                <div class="xw-color-13 xw-ellipsis" v-if="item.desc">{{item.desc}}</div>
              </div>
            </div>
            <div class="LUR-div xw-flex xw-flex-align">
              <div class="xw-flex-W1 xw-ellipsis"><span class="xw-color-13">用户编号：</span><a @click="getAuditFun(2, item)">{{item.sn}}</a></div>
              <div class="xw-flex-W1 xw-ellipsis"><span class="xw-color-13">注册时间：</span>{{item.created_at}}</div>
            </div>
            <div class="LUR-div xw-flex xw-flex-align">
              <div class="xw-flex-W1 xw-ellipsis"><span class="xw-color-13">业务负责：</span>{{item.leader}}</div>
              <div class="xw-flex-W1 xw-ellipsis"><span class="xw-color-13">注册手机：</span><a @click="getAuditFun(3, item)">{{item.telphone}}</a></div>
            </div>
            <div class="LUR-div xw-flex xw-flex-align">
              <div class="xw-flex-W1 xw-ellipsis"><span class="xw-color-13">上级编号：</span>{{item.parent_sn}}</div>
              <div class="xw-flex-W1 xw-ellipsis"><span class="xw-color-13">注册手机：</span>{{item.parent_telphone}}</div>
            </div>
            <div class="LUR-div xw-flex">
              <span class="xw-color-13">合作意向：</span>
              <dl class="LUR-intrend xw-flex-W1 xw-float" v-if="item.intends && Number(item.intends.length) > 0">
                <dt class="xw-float-W2 xw-flex xw-flex-align" :class="{'active': tend.light}" v-for="(tend, num) in item.intends">
                  <em :class="[tend.light ? 'fa fa-square-check' : 'fal fa-square-check']"></em>
                  <span>{{tend.text}}</span>
                </dt>
              </dl>
            </div>
            <div class="LUR-btn xw-act-bg xw-flex xw-flex-align xw-flex-justify" @click="getAuditFun(4, item)">
              <span class="xw-color-12">交费记录</span>
              <i class="fal fa-angle-right"></i>
            </div>
            <div class="LUR-btn xw-Tfg xw-flex xw-flex-align xw-flex-justify">
              <span class="xw-color-12">信息审核</span>
              <div class="USS-check" @click="getAuditFun(5, item)"><input type="checkbox" class="a-switch" v-model="item.isOpenStoped"/><label></label></div>
            </div>
            <div class="LUR-btn xw-Tfg xw-flex xw-flex-align xw-flex-justify">
              <span class="xw-color-12">市场推广员</span>
              <div class="LUR-sel xw-flex xw-flex-align">
                <p class="xw-color-13" v-if="item.salerTime">有效期：{{item.salerTime}}</p>
                <div class="USS-check" @click="getAuditFun(7, item)"><input type="checkbox" class="a-switch" v-model="item.isOpenSaler"/><label></label></div>
              </div>
            </div>
            <div class="LUR-btn xw-Tfg xw-flex xw-flex-align xw-flex-justify">
              <div class="xw-flex-W1">
                <div class="xw-flex xw-flex-align xw-flex-justify">
                  <span class="xw-color-12">区域运营商</span>
                  <p class="xw-color-13" v-if="item.salesmanTime">有效期：{{item.salesmanTime}}</p>
                </div>
                <div class="LUR-city xw-ellipsis" v-if="item.isOpenSalesman">代理地区：{{item.agentCity}}</div>
              </div>
              <div class="USS-check" @click="getAuditFun(6, item)"><input type="checkbox" class="a-switch" v-model="item.isOpenSalesman"/><label></label></div>
            </div>
            <div class="LUR-btn xw-Tfg xw-flex xw-flex-align xw-flex-justify">
              <span class="xw-color-12">战略合作商</span>
              <div class="LUR-sel xw-flex xw-flex-align">
                <p class="xw-color-13" v-if="item.exhibitionTime">有效期：{{item.exhibitionTime}}</p>
                <div class="USS-check" @click="getAuditFun(8, item)"><input type="checkbox" class="a-switch" v-model="item.isOpenExhibition"/><label></label></div>
              </div>
            </div>
            <div class="LUR-btn xw-Tfg xw-flex xw-flex-align xw-flex-justify">
              <span class="xw-color-12">中国批发商</span>
              <div class="USS-check" @click="getAuditFun(9, item)"><input type="checkbox" class="a-switch" v-model="item.isOpenWhole"/><label></label></div>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <sliding-view ref="sliding"/>
    <preImg-view ref="preImg"/>
    <picker-view ref="pickerCity"/>
    <layer-view ref="layer"/>
    <layer-view ref="layerBox"/>
  </div>
</template>

<style scoped>
/* ---- */
.forNav { margin-top: -0.8rem; height: 4rem; }
.FNV-menu { margin-left: 1rem; }
.FNV-menu .swiper { height: 100%; }

/* ---- */
.list-user li { position: relative; margin: 1rem 1rem 0; padding: 1.2rem 1rem 0.2rem; overflow: hidden; }
.list-user li:nth-of-type(1) { margin-top: 0; }
.LUR-con { margin: 0 0 1rem; }
.LUR-avar { margin: 0 1rem 0 0; width: 7.5rem; height: 7.5rem; }
.LUR-name { text-align: justify; }
.LUR-name h1 { line-height: 2.5rem; font-size: 1.7rem; }
.LUR-name div { line-height: 2.5rem; }
.LUR-div { line-height: 2.5rem; font-size: 1.3rem; }
.LUR-intrend dt em { margin-right: 0.5rem; font-size: 1.7rem; color: #d7d7d7; }
.LUR-intrend dt.active, .LUR-intrend dt.active em { color: #ff5722; }
.LUR-btn { padding: 1rem 0; overflow: visible; }
.LUR-btn span { font-size: 1.6rem; }
.LUR-btn i { font-size: 2rem; color: #bbbbbb; }
.LUR-sel { overflow: visible; }
.LUR-city { padding: 0.5rem 0 0; }
</style>
